package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.BriefMemberInfoBean;
import com.shop2cn.iapi.member.parameter.BriefMemberInfoResp;
import com.shop2cn.iapi.member.parameter.CollectionMemberInfoBean;
import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.service.BriefMemberInfoCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmember.Member;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
/**
*简版会员详情
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BriefMemberInfo{
	private static BriefMemberInfoBean briefmemberinfoBean;
	private static BriefMemberInfoCall briefmemberinfoCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("简版会员详情");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		briefmemberinfoBean=new BriefMemberInfoBean();
		briefmemberinfoCall=new BriefMemberInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(briefmemberinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_001() {
		Logger.start(true,"简版会员详情成功");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(null,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(false,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
			Logger.verifyEquals(false,BriefMemberInfoResp.getNeedInvitationCode(), "验证getNeedInvitationCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BriefMemberInfo_002() {
		Logger.start(true,"不输入userid失败");
		try {
			briefmemberinfoBean.setShopId(shopid);
//			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("400", briefmemberinfoCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BriefMemberInfo_003() {
		Logger.start(true,"不输入shopid失败");
		try {
//			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(1);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("400", briefmemberinfoCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BriefMemberInfo_004() {
		Logger.start(true,"输入shopid和userid不匹配失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId+1);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			Logger.verifyEquals(null, BriefMemberInfoResp.getMemberId(), "没查到用户");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_005() {
		Logger.start(true,"简版会员详情成功,包含会员收集信息");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			CollectionMemberInfoBean collectionmemberinfoBean=new CollectionMemberInfoBean();
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setRealName("rname");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setWechatName("wxname");
			GodMemberService.collectionmemberinfoCall(collectionmemberinfoBean);
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(null,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(collectionmemberinfoBean.getSex(),BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(collectionmemberinfoBean.getWechatName(),BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(false,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_006() {
		Logger.start(true,"简版会员详情成功,包含手机号");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(mobile,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(false,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_007() {
		Logger.start(true,"简版会员详情成功,包含积分");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
//			GodMemberService.mchSetOpenPoints(GodMemberService.initSetPointsBean(shopid));
			Integer points=10;
			GodMemberService.sendPoints(memid, shopid, points);
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(points,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(null,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			//由于执行顺序不同可能会有不同结果
//			Logger.verifyEquals(false,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_008() {
		Logger.start(true,"简版会员详情成功,需要关联手机号");
		try {
			Integer shopid2 = GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid2,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.setCollectionMobile(shopid2, true);
			briefmemberinfoBean.setShopId(shopid2);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(null,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(true,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_009() {
		Logger.start(true,"简版会员详情成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			GodMemberWapper.updateMchmemberConfigNeedInvitationCode(shopid, false);
			//不开这个开关 返回不需要邀请码
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(null,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(true,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
			Logger.verifyEquals(false,BriefMemberInfoResp.getNeedInvitationCode(), "验证getNeedInvitationCode");
			//开这个开关 返回需要邀请码
			GodMemberWapper.updateMchmemberConfigNeedInvitationCode(shopid, true);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			Logger.verifyEquals(true,BriefMemberInfoResp.getNeedInvitationCode(), "验证getNeedInvitationCode");
			
			//绑定了手机 返回不需要邀请码
			GodMemberService.bindMobile(shopid, userId, TestDataManager.getPhoneNum(), 1);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			Logger.verifyEquals(false,BriefMemberInfoResp.getNeedInvitationCode(), "验证getNeedInvitationCode");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_010() {
		Logger.start(true,"简版会员详情成功-是否绑定手机,对应客服编号");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//开启邀请制
            GodMemberService.setCollectionMobile(shopid, true);
            GodMemberService.setInvitationCodeCall(shopid, true, 0);
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			Integer csId=1;
			//绑定了手机 返回不需要邀请码
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile, csId);
			
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(mobile,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(false,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
			Logger.verifyEquals(false,BriefMemberInfoResp.getNeedInvitationCode(), "验证getNeedInvitationCode");
			Logger.verifyEquals(true,BriefMemberInfoResp.getBindMobile(), "验证getBindMobile");
			Logger.verifyEquals(csId,BriefMemberInfoResp.getCsId(), "验证getCsId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BriefMemberInfo_011() {
		Logger.start(true,"简版会员详情成功-查询分销员id");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			Integer csid=100;
			GodMemberService.bindMobile(shopid, userId, mobile,csid);
			
			briefmemberinfoBean.setShopId(shopid);
			briefmemberinfoBean.setUserId(userId);
			briefmemberinfoCall.setData(briefmemberinfoBean);
			briefmemberinfoCall.callService();			
			Logger.verifyEquals("200", briefmemberinfoCall.getString("code"), "验证code");
			BriefMemberInfoResp BriefMemberInfoResp = briefmemberinfoCall.getBriefMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(BriefMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,BriefMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),BriefMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(mobile,BriefMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,BriefMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,BriefMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(false,BriefMemberInfoResp.getCollectionMobile(), "验证getCollectionMobile");
			Logger.verifyEquals(false,BriefMemberInfoResp.getNeedInvitationCode(), "验证getNeedInvitationCode");
			Logger.verifyEquals(duserId,BriefMemberInfoResp.getDsId(), "验证getDsId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}